<template>
	<view class="pages">
		<!-- 使用自定义导航栏组件 -->
		<navBar title="新师汇" bgColor="#156ed2" @getHeadHeight="getHeadHeight" :backIcon="false" path='/pages/index/index'>
		</navBar>
		<view class="swiper">
			<u-swiper :list="slide"  @click="click"></u-swiper>
		</view>
<view class="notice">
	<u-notice-bar :more-icon="true" :list="notice" type="primary"></u-notice-bar>
	<view class="check-icon my-3" @click="toSearch">
		<image src="../../static/images/check-index.png" mode="widthFix"></image>
	</view>
	<view class="notify-list">	
		<view class="row" v-for="(item, index) in news" :key="index" @click="toDetail(item.id)">
			<view class="carrier">
				<view class="notify-wrapper">
					<view class="title in1line">{{item.title}}</view>
					<view class="content in2line">{{item.description}}</view>
					<view class="time">{{item.created_time}}</view>
					<view class="type">
						<view class="uni-tag uni-small bg-blue">{{item.category.title}}</view>
					</view>
					<uni-tag class="type" type="error" text="公告" size="small" />
					<view class="un-read bg-blue">
					</view>
				</view>
			</view>
		</view>
	</view>
	<view class="f-divider"></view>
	<view class="flex align-center justify-center py-3">
		<text class="font text-secondary">上位加载更多</text>
	</view>
</view>
<BottomBar :selected='selected'></BottomBar>
	</view>
</template>
<script>
	import $C from '../../static/common/config.js';
	export default {
		data() {
			return {
				slide: [],
				notice: [],
				news:[],
				HeadNavHeight: 0,
				page:'',
				selected: 0
			}

		},
		onLoad() {
			this.getNews()
			this.getSlide()
			this.getNotice()
		},
		onPullDownRefresh() {
			this.page = 1
			this.getNews().then(res=>{
				uni.showToast({
					title:'刷新成功',
					icon:'none'
				});
				uni.stopPullDownRefresh()
			}).catch(err=>{
				uni.stopPullDownRefresh()
			})
		},
		onReachBottom() {
			
		},
		methods: {
			getNews(){
				return this.$H.get('/article/list/1', {}, {}).then(res => {
					console.log(res);
					this.news = res.data
					console.log(this.news)
				});
			},
			getNotice(){
				this.$H.get('/article/list/6', {}, {}).then(res => {
					console.log(res);
					res.data.map(item =>{
						this.notice.push(item.title)
					})
					console.log(this.notice)
				});
			},
			getSlide(){
				this.$H.get('/slide/list', {}, {}).then(res => {
					console.log(res);
					this.slide = res.data.map(item => {
						return {
							image:$C.imageUrl + item.images,
							title:item.title,
							link:item.link
						};
					});
			})
			},
			toDetail(id){
				uni.navigateTo({
					url:'/pages/article/article?id=' + id
				})
			},
			toSearch(){
				uni.switchTab({
					url:'/pages/search/search'
				})
			},
			// 导航栏高度(单位px)
			getHeadHeight(e) {
				this.HeadNavHeight = e
				console.log(this.HeadNavHeight);
			},
			click(e) {
				console.log(this.slide[e]);
				if(this.slide[e].link){
					uni.navigateTo({
						url:this.slide[e].link
					})
					console.log(this.slide[e].link);
				}
			},
		}
	}
</script>

<style>
	.pages{
		padding-bottom: 80rpx;
	}
	.swiper {
		padding: 0rpx;
	}
	.check-icon{
		text-align: center;
	}
	.check-icon image{
		border-radius: 20px;
		width: 60%;
	}
</style>